﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using CarEvaluationANN;

namespace UnitTest
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            string[] lines = File.ReadAllLines(@".\DataSetFiles\DataSets\TrainSet80%csv.csv");

            var csvTable = new CSVTable(lines);
            List<string> inputHeaderList =
                csvTable.HeaderRow.GetRow().Where(t => Regex.IsMatch(t, @"X\d+", RegexOptions.IgnoreCase)).ToList();
            List<string> outputHeaderList =
                csvTable.HeaderRow.GetRow().Where(t => Regex.IsMatch(t, @"Y\d+", RegexOptions.IgnoreCase)).ToList();

            var ts = new List<DataSetUnit>();
            for (int i = 1; i < csvTable.RowCount; i++)
            {
                var inputs = new List<double>();
                var outputs = new List<double>();
                inputHeaderList.ForEach(x => inputs.Add(UtilityConvert.GetDouble(csvTable[i, x])));
                outputHeaderList.ForEach(y => outputs.Add(UtilityConvert.GetDouble(csvTable[i, y])));

                ts.Add(new DataSetUnit(inputs.ToArray(), outputs.ToArray()));
            }
            var nnController = new NeuralNetworkController(ts);
            //wrapper.HiddenLayerType = HiddenLayerType.Sigmoid;
            nnController.Train();

            string temp = nnController.ErrorList.Last().ToString("0.000000");

            Console.WriteLine(temp);
            Console.ReadLine();
            //var indices = new double[nnController.Cycles];
            //for (var i = 0; i < nnController.Cycles; i++)
            //{
            //    indices[i] = i;
            //}
        }
    }
}